package sfin.swt.composite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.swtchart.ISeries;
import org.swtchart.ISeries.SeriesType;
import org.swtchart.ISeriesSet;
import org.swtchart.internal.series.BarSeries;

public class ReceitaVsDespesaChartComposite extends Composite {

	public ReceitaVsDespesaChartComposite(Composite parent, int style) {
		super(parent, style);
	}


	public static void main(String[] args) {

		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		shell.setLayout(new FormLayout());

		Chart chart = new Chart(shell, SWT.NONE);
		chart.setOrientation(SWT.HORIZONTAL);

		FormData formData = new FormData();
		formData.top = new FormAttachment(0);
		formData.left = new FormAttachment(0);
		formData.right = new FormAttachment(100);
		formData.bottom = new FormAttachment(100);
		chart.setLayoutData(formData);

		double[] ySeries = new double[]{1000,150,140,300};
		
		ISeriesSet seriesSet = chart.getSeriesSet();
		ISeries series = seriesSet.createSeries(SeriesType.BAR, "Receitas");
		series.setYSeries(ySeries);
		BarSeries barSerie = (BarSeries) (series);
		barSerie.setBarColor(new Color(display,new RGB(232, 231, 230)));
		
		series = seriesSet.createSeries(SeriesType.BAR, "Despesas");
		ySeries = new double[]{300,200,400,100};
		series.setYSeries(ySeries);

		barSerie = (BarSeries) (series);
		barSerie.setBarColor(new Color(display,new RGB(100,99, 98)));
		
		series = seriesSet.createSeries(SeriesType.BAR, "Investimentos");
		ySeries = new double[]{100,100,100,50};
		series.setYSeries(ySeries);

		barSerie = (BarSeries) (series);
		barSerie.setBarColor(new Color(display,new RGB(45, 155, 45)));
		
		chart.getTitle().setText("teste");
		chart.getAxisSet().adjustRange();
		
		IAxis xAxis = chart.getAxisSet().getXAxis(0);
		xAxis.setCategorySeries(new String[]{"Jan","Fev","Mar","Abr"});
		xAxis.enableCategory(true);
		
		xAxis.getTitle().setText("ACSIS XIS");
		
		chart.getAxisSet().getYAxis(0).getTitle().setText("ACSIS YPSLON");
		
		shell.open();
		
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();

		}

	}
}
